Skip to content

fix: OpenAPI 서버 URL 설정 및 Vote 통합 테스트 추가#171

Open
Junhyukkkk wants to merge 2 commits into
developfrom
fix/openapi-config
Open

fix: OpenAPI 서버 URL 설정 및 Vote 통합 테스트 추가#171
Junhyukkkk wants to merge 2 commits into
developfrom
fix/openapi-config

Conversation

@Junhyukkkk
Copy link
Copy Markdown
Member

@Junhyukkkk Junhyukkkk commented May 27, 2026

📌 관련 이슈

  • closes #

🔍 작업 내용

Swagger UI가 프로덕션 환경에서 올바른 서버 URL을 사용하지 못하는 문제를 수정하고,
Vote 도메인에 대한 통합 테스트를 추가합니다.

📝 변경 사항

  • OpenApiConfig: springdoc.server-url 환경변수를 주입받아 값이 존재할 경우 OpenAPI 서버 목록에 동적으로 등록
  • application-prod.yml: 프로덕션 서버 URL(https://api.vs.io.kr)을 springdoc.server-url로 명시
  • VoteApiIntegrationTest: Vote API 전체 플로우에 대한 통합 테스트 추가
  • VoteRepositoryIntegrationTest: Vote Repository 쿼리에 대한 통합 테스트 추가

💬 리뷰어에게

  • serverUrl이 비어 있을 경우 서버 목록을 설정하지 않아 로컬 환경에서는 기존 동작이 그대로 유지됩니다.
  • 통합 테스트는 src/integrationTest 소스셋에 위치합니다.

Summary by CodeRabbit

릴리스 노트

  • Tests

    • 투표 API의 생성 및 조회 기능에 대한 통합 테스트 추가로 안정성 강화
    • 투표 저장소의 저장, 조회, 필터링 및 정렬 기능에 대한 통합 테스트 추가
  • Chores

    • 운영 환경에서의 API 문서 서버 URL 설정 개선

Review Change Stack

@Junhyukkkk Junhyukkkk self-assigned this May 27, 2026
@github-actions github-actions Bot added the bug label May 27, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

Walkthrough

투표 기능의 API 계층(생성/조회 엔드포인트) 및 데이터 계층(Repository의 저장/조회/필터링/정렬) 통합 테스트를 추가하고, OpenAPI 서버 URL을 환경별로 구성하는 변경입니다.

Changes

Vote Feature Integration Testing

Layer / File(s) Summary
Vote API Integration Tests
src/integrationTest/java/com/ject/vs/vote/adapter/web/VoteApiIntegrationTest.java
MockMvc 기반으로 /api/votes POST(생성) 및 GET(상세조회) 엔드포인트를 검증합니다. 테스트 인프라(Spring Boot 통합 테스트 설정, 보안 컨텍스트 헬퍼, 테스트 사용자)를 구성하고, 인증된/미인증 사용자의 요청 처리, 응답 필드(endAt, status, title, voteId), 데이터베이스 저장 여부를 확인합니다. 다양한 duration 값에 대한 종료 시각 계산과 전체 생성→조회 플로우도 검증합니다.
Vote Repository Integration Tests
src/integrationTest/java/com/ject/vs/vote/domain/VoteRepositoryIntegrationTest.java
Spring Data JPA 테스트로 Vote 및 VoteOption 엔티티의 저장, 필드 매핑의 정확성을 검증합니다. 고정 Clock을 사용해 시간 기반 로직(상태 판정, 종료 시각 계산)을 결정적으로 테스트하며, findOngoingVotes, findOngoingOrderByEndAtAsc, findAllByOrderByIdDesc 등 조회 메서드의 필터링 및 정렬 동작과 cacheAiInsight로 AI 인사이트 저장/조회 동작을 확인합니다.

OpenAPI Documentation Configuration

Layer / File(s) Summary
OpenAPI Server URL Configuration
src/main/java/com/ject/vs/config/OpenApiConfig.java, src/main/resources/application-prod.yml
OpenApiConfig에서 springdoc.server-url 프로퍼티가 비어있지 않을 때만 OpenAPI 스키마의 servers 섹션에 Server를 추가하도록 변경하고, 운영 프로파일에 https://api.vs.io.kr을 서버 URL로 설정합니다. 이를 통해 Swagger UI에서 환경별 정확한 서버 주소를 표시합니다.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • JECT-Study/JECT2-4th-Server#136: VoteRepositoryIntegrationTestAiInsightCacheTest가 AI 인사이트 저장/조회 동작을 검증하는데, 이는 해당 PR의 AiInsightService 및 Gemini 빈 조건부 등록 변경과 직접 연결됩니다.
  • JECT-Study/JECT2-4th-Server#141: VoteRepositoryIntegrationTest의 정렬/상태 필터링 테스트(findOngoingOrderByEndAtAsc, findAllByOrderByIdDesc, getStatus)는 해당 PR의 VoteRepository 쿼리 메서드 추가와 직접적으로 대응됩니다.

Suggested labels

test, integration-test

Suggested reviewers

  • KII1ua
  • tlarbals824

🐰 투표 기능, 이제 테스트로 검증하네요!
API부터 DB까지 흐름을 따라가며,
시간도 맞추고 상태도 확인하고—
마지막에 AI 인사이트까지 캐싱하네요.
문서도 갈아입고 준비 완료! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목이 변경사항의 주요 내용을 명확히 요약하고 있습니다. OpenAPI 서버 URL 설정 수정과 Vote 통합 테스트 추가라는 두 가지 핵심 변경사항을 간결하게 나타냅니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/openapi-config

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

빌드 실패
코드를 확인해주세요.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/integrationTest/java/com/ject/vs/vote/adapter/web/VoteApiIntegrationTest.java (2)

247-249: ⚡ Quick win

사용되지 않는 변수를 제거하세요.

responseBody 변수가 선언되었지만 사용되지 않습니다. 이 라인을 제거하거나, 응답에서 voteId를 파싱하여 사용하는 것이 일관성 있습니다.

♻️ 제안
-            // voteId 추출
-            String responseBody = createResult.getResponse().getContentAsString();
-            Long voteId = voteRepository.findAll().get(0).getId();
+            // voteId 추출
+            Long voteId = voteRepository.findAll().get(0).getId();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/integrationTest/java/com/ject/vs/vote/adapter/web/VoteApiIntegrationTest.java`
around lines 247 - 249, Remove the unused local variable responseBody declared
from createResult.getResponse().getContentAsString(); either delete that line or
replace its usage by parsing the created voteId from the response body and using
it instead of fetching voteRepository.findAll().get(0).getId(); update the test
to use the parsed voteId (from createResult) for subsequent assertions or remove
the unused responseBody altogether so only voteId (from either the response or
repository) remains in VoteApiIntegrationTest.

180-216: ⚡ Quick win

테스트 이름과 실제 검증 내용이 일치하지 않습니다.

테스트 이름은 "endAt이 정확히 계산된다"를 주장하지만, 실제로는 isNotEmpty()isNotNull()만 검증합니다. VoteRepositoryIntegrationTest처럼 각 duration에 대해 계산된 endAt 값을 명시적으로 검증해야 합니다.

♻️ 계산된 endAt 값을 검증하는 개선안
     `@Test`
-    `@DisplayName`("다양한 duration으로 투표 생성 시 endAt이 정확히 계산된다")
-    void 다양한_duration으로_투표_생성시_endAt_계산_확인() throws Exception {
+    `@DisplayName`("다양한 duration으로 투표 생성 시 endAt이 응답에 포함된다")
+    void 다양한_duration으로_투표_생성시_endAt_포함_확인() throws Exception {

또는 실제 계산 검증을 추가:

// 각 duration별로 endAt 차이를 검증
Map<String, Duration> durationMap = Map.of(
    "HOURS_1", Duration.ofHours(1),
    "HOURS_6", Duration.ofHours(6),
    "HOURS_12", Duration.ofHours(12),
    "HOURS_24", Duration.ofHours(24)
);

for (Vote vote : votes) {
    // title에서 duration 추출 후 endAt 차이 검증
    Instant expectedMinEndAt = vote.getCreatedAt().plus(durationMap.get(vote.getTitle().replace("투표 ", "")));
    assertThat(vote.getEndAt()).isAfterOrEqualTo(expectedMinEndAt);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/integrationTest/java/com/ject/vs/vote/adapter/web/VoteApiIntegrationTest.java`
around lines 180 - 216, The test method 다양한_duration으로_투표_생성시_endAt_계산_확인() only
asserts presence of endAt but the name claims precise calculation; update the
test to compute expected durations and assert endAt is correctly computed per
vote. After creating votes with mockMvc in that test, build a Map<String,
Duration> for "HOURS_1","HOURS_6","HOURS_12","HOURS_24", load persisted Vote
entities via voteRepository.findAll(), extract the duration key from
vote.getTitle() (or from the request context), then assert
vote.getEndAt().isAfterOrEqualTo(vote.getCreatedAt().plus(expectedDuration)) (or
sufficiently close) for each Vote to validate exact endAt calculation rather
than only non-null checks. Ensure assertions reference the test method name
다양한_duration으로_투표_생성시_endAt_계산_확인, Vote.getCreatedAt(), and Vote.getEndAt().
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@src/integrationTest/java/com/ject/vs/vote/adapter/web/VoteApiIntegrationTest.java`:
- Around line 247-249: Remove the unused local variable responseBody declared
from createResult.getResponse().getContentAsString(); either delete that line or
replace its usage by parsing the created voteId from the response body and using
it instead of fetching voteRepository.findAll().get(0).getId(); update the test
to use the parsed voteId (from createResult) for subsequent assertions or remove
the unused responseBody altogether so only voteId (from either the response or
repository) remains in VoteApiIntegrationTest.
- Around line 180-216: The test method 다양한_duration으로_투표_생성시_endAt_계산_확인() only
asserts presence of endAt but the name claims precise calculation; update the
test to compute expected durations and assert endAt is correctly computed per
vote. After creating votes with mockMvc in that test, build a Map<String,
Duration> for "HOURS_1","HOURS_6","HOURS_12","HOURS_24", load persisted Vote
entities via voteRepository.findAll(), extract the duration key from
vote.getTitle() (or from the request context), then assert
vote.getEndAt().isAfterOrEqualTo(vote.getCreatedAt().plus(expectedDuration)) (or
sufficiently close) for each Vote to validate exact endAt calculation rather
than only non-null checks. Ensure assertions reference the test method name
다양한_duration으로_투표_생성시_endAt_계산_확인, Vote.getCreatedAt(), and Vote.getEndAt().

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d1df79e3-c0f4-48cb-abff-92276c7ce2a3

📥 Commits

Reviewing files that changed from the base of the PR and between 0e5c1e5 and 51d5276.

📒 Files selected for processing (4)
  • src/integrationTest/java/com/ject/vs/vote/adapter/web/VoteApiIntegrationTest.java
  • src/integrationTest/java/com/ject/vs/vote/domain/VoteRepositoryIntegrationTest.java
  • src/main/java/com/ject/vs/config/OpenApiConfig.java
  • src/main/resources/application-prod.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant